#!/usr/bin/python3
import os
import time
import threading
from PIL import Image, ImageSequence
from PIL import ImageFont, ImageDraw
from luma.core.interface.serial import i2c
from luma.core.render import canvas
from luma.oled.device import ssd1306
# import pcf8591_library
import RPi.GPIO as gpio

gpio.setmode(gpio.BCM)
serial = i2c(port=1, address=0x3C)
device = ssd1306(serial, width=128, height=64)

# img1= Image.open("../landscape128x64.jpg")
# img1 = img1.convert("1")
# img1.save("bt.bmp")
# img1.close()

imgb=Image.open("../ksu.jpg")
# imgb.resize((128,64))
imgb=imgb.convert("1")
font = ImageFont.truetype("new.otf",10)

while True:
    # b =input("abab")
    with canvas(device) as draw:
        dtime = time.strftime("%Y年\n%m月%d日")
        dtime1= time.strftime("%p:%I时\n%M分%S秒")
        # # draw.rectangle(device.bounding_box,outline="white",fill="black")
        draw.bitmap((0,0),imgb,fill="white")
        draw.text((65,0),dtime,fill="white",font=font)
        draw.text((65,30),"时间:"+dtime1,fill="white",font=font)
        # draw.text((65,60),"FPS:"+b,fill="white")
        # for i in range(25,64):
        #     # i=0.5*i
        #     draw.point((0.2222222222222222*(i*i)+-19.555555555555554*i+430.2222222222222,i),fill="white")
            
        
        # draw.bitmap((64,0),imgb,fill="white")
    # time.sleep(100)
# imgb.close()